package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName ShopController
 * @Description 店铺相关的控制层
 * @Author sld
 * @Date 2024/7/10 9:01
 * Version 1.0
 **/
@RestController
@RequestMapping( "/admin/shop")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopController {

    private static final String KEY = "shop_statsu";

    @Resource
    private RedisTemplate   redisTemplate;

    /**
     *
     *  修改店铺状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("修改店铺状态")
    public Result updateStatus(@PathVariable Integer status) {
        log.info("修改店铺状态："+(status==1?"营业中":"打烊中"));
        // 设置店铺状态
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus() {
        // 从redis中获取数据
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        // 输出日志
        log.info("获取店铺状态："+(status==1?"营业中":"打烊中"));
        // 返回结果
        return Result.success(status);
    }
}
